<?php
namespace Home\Controller;
use Think\Controller;

class OtherController extends Controller {
    public function broadcastIndex(){//直播预约
        indexRequest($_REQUEST);//测算首页接收数据处理
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            cookie('wxlogin',0);
        }else{
            cookie('wxlogin',1);
            cookie('http','http');
            getToken();
            getTicket();
            $id = cookie('APPID');
            $noncestr=noncestr(15);
            $timestamp=time();
            $ticket= S('ticket'.$id);
            $wzurl=wxJsdkData();
            $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");
//            dump("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");
//            dump($signature);

            $this->assign('appid',cookie('APPID'));
            $this->assign('timestamp',$timestamp);
            $this->assign('noncestr',$noncestr);
            $this->assign('signature',$signature);

            if(!empty($_REQUEST['code'])){
                cookie('code',$_REQUEST['code'],7100);
            }
            getCode($wzurl);
            getOopenid();
            cookie('uid',cookie('openid'));

        }
        if($_REQUEST['lid']){
            cookie('lid',$_REQUEST['lid']);
        }else{
            cookie('lid',575);
        }
        $lid=cookie('lid');
        $uid=cookie('uid');

        $strData='';
        foreach($_REQUEST as $key=>$value){
            if($key!='lid'){
                $strData.='&'.$key.'='.$value;
            }
        }

        redirect("http://web.pingushi.net/appoint/index.html?lid={$lid}&openid={$uid}{$strData}");
        //redirect("http://web.zhimingds.com/appoint/index.html?lid={$lid}&openid={$uid}{$strData}");
//        redirect("https://sm.ddznzj.com/sm/media/chat/index.html?lid={$lid}&openid={$uid}{$strData}");

        $url="http://api.ddznzj.com/acliveroominfo/?lid={$lid}";
        $data=curlGet($url);
        $arr=json_decode($data,true);
        $this->assign('arr',$arr['content']);
        $this->display("Other/broadcastIndex");
    }
    public function broadcastData(){//首页直播间信息
        $lid=$_REQUEST['lid'];
        if(empty($lid)){$lid=575;}
        $url="http://api.ddznzj.com/acliveroominfo/?lid={$lid}";
        $data=curlGet($url);
        echo $data;
    }
    public function submitted(){//提交记录
        $uid=cookie('uid');
        $lid=cookie('lid');
        if($_REQUEST['openid']){$uid=$_REQUEST['openid'];}
        if($_REQUEST['lid']){$lid=$_REQUEST['lid'];}
        $phone=$_REQUEST['phone'];
        $addr=$_REQUEST['addr'];
        $birthday=$_REQUEST['birthday'];
        $sex=$_REQUEST['sex'];
        $username=$_REQUEST['username'];
        judgeData(array($phone,$addr,$birthday,$username,$sex),$_REQUEST);
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        if(strpos($user_agent, 'iPhone')||strpos($user_agent, 'iPad')){//IOS端
            $clienttype=2;
        }else{
            $clienttype=1;
        }

        $strData=array(
            'openid'=>$uid,
            'phone'=>$phone,
            'addr'=>$addr,
            'birthday'=>$birthday,
            'sex'=>$sex,
            'lid'=>$lid,
            'username'=>$username,
            'clienttype'=>$clienttype,
        );
        $url="http://api.ddznzj.com/commitreserveinfo/";
        $data=curlPost($url,$strData);
        echo $data;
    }
    public function selectYy(){//查看预约
        $uid=cookie('uid');
        $lid=cookie('lid');
        if($_REQUEST['openid']){$uid=$_REQUEST['openid'];}
        if($_REQUEST['lid']){$lid=$_REQUEST['lid'];}
        judgeData(array($uid,$lid),$_REQUEST);
        $url="http://api.ddznzj.com/reservestatus/?openid={$uid}&lid={$lid}";

        $data=curlGet($url);
        echo $data;
    }
    public function shareYy(){//预约分享
        $uid=cookie('uid');
        $lid=cookie('lid');
        if($_REQUEST['openid']){$uid=$_REQUEST['openid'];}
        if($_REQUEST['lid']){$lid=$_REQUEST['lid'];}
        judgeData(array($uid,$lid),$_REQUEST);
        $url="http://api.ddznzj.com/commitreservestatus/?openid={$uid}&lid={$lid}";
        $data=curlGet($url);
        echo $data;
    }
    public function shareData(){//分享参数获取
        $url=$_REQUEST['shareUrl'];
        judgeData(array($url));
        cookie('getTokenType','qwxlcs');//趣测心理公众号
        getToken();
        getTicket();
        $id = cookie('APPID');
        $noncestr=noncestr(15);
        $timestamp=time();
        $ticket= S('ticket'.$id);
        $wzurl=$url;

        $signature=sha1("jsapi_ticket={$ticket}&noncestr={$noncestr}&timestamp={$timestamp}&url={$wzurl}");

        $Arr=array(
            'appid'=>$id,
            'timestamp'=>$timestamp,
            'noncestr'=>$noncestr,
            'signature'=>$signature
        );
        echo json_encode($Arr);
    }
}